package com.caigou.modules.article.ui

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.caigou.comm.base.bean.AppBackgroundInfo
import com.caigou.comm.base.constants.AppConstants
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseReplyActivity
import com.caigou.comm.base.ext.observe
import com.caigou.modules.article.bean.ArticleItemBean
import com.caigou.modules.article.viewmodel.ArticleViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.io.File

/**
 * @author #Suyghur.
 * Created on 2021/11/27
 */
@Route(path = RouterPath.Article.PAGE_ARTICLE_REPLY)
@AndroidEntryPoint
class ArticleReplyActivity : BaseReplyActivity() {

    private val articleViewModel: ArticleViewModel by viewModels()

    @Autowired(name = AppConstants.ARTICLE_ITEM_BEAN)
    lateinit var articleItemBean: ArticleItemBean

    override fun initView() {
        super.initView()
        binding.replyBtnSubmit.setOnClickListener {
            val content = binding.replyEtContent.text.toString()
            val files: MutableList<File> = mutableListOf()
            urls.forEach {
                files.add(File(it))
            }
            articleViewModel.setArticleReply(
                content, files, AppBackgroundInfo.instance.userBean!!.userId,
                articleItemBean.userInfo.userId, articleItemBean.dataId
            )
        }
    }

    override fun observeViewModel() {
        observe(articleViewModel.articleReplyLiveData, ::handleSetReply)
    }
}